﻿//========================================================================
// *作者：海盗猫  主页：ilplay.com
// *脚本：EditorUIFrame
// *描述：EditorUIFrame
// *?2024 HDMCode . All rights reserved.
//* ======================================================================
using HDMCode.FrameEditor;
using UnityEditor;
using UnityEngine;

namespace HDMCode.UIFrameEditor
{
    public class EditorUIFrame
    {
        private static SerializedObject m_SerializedObject;
        
        [HDMEditorMenu("核心工具", "UI框架", "UI.png")]
        public static void Main()
        {
            HDMEditorHelper.DrawTileLable("UI框架设置");
            
            using (new UnityEditor.EditorGUILayout.HorizontalScope()) 
            {
                GUILayout.Label("脚本路径", HDMEditorStyle.styleContent, new[] { GUILayout.Width(70), GUILayout.Height(20) });
                UnityEditor.EditorGUILayout.HelpBox(EditorBaseDate.Setting.ScriptPath, MessageType.None);
                HDMEditorHelper.DrawButton("选择路径", "", () => 
                {
                    EditorBaseDate.Setting.ScriptPath = EditorUtility.OpenFolderPanel("选择路径", "", "");
                });
            }
            
            using (new UnityEditor.EditorGUILayout.HorizontalScope()) 
            {
                GUILayout.Label("资源路径", HDMEditorStyle.styleContent, new[] { GUILayout.Width(70), GUILayout.Height(20) });
                UnityEditor.EditorGUILayout.HelpBox(EditorBaseDate.Setting.AssetsPath, MessageType.None);
                HDMEditorHelper.DrawButton("选择路径", "", () => 
                {
                    EditorBaseDate.Setting.AssetsPath = EditorUtility.OpenFolderPanel("选择路径", "", "");
                });
            }
            
            HDMEditorHelper.DrawTileLable("分组设置");
            m_SerializedObject = new SerializedObject(EditorBaseDate.Setting);
            m_SerializedObject.Update();
            var groups = m_SerializedObject.FindProperty("Groups");
            UnityEditor.EditorGUILayout.PropertyField(groups, true);
            m_SerializedObject.ApplyModifiedProperties();
            
            if (GUI.changed)
                EditorUtility.SetDirty(EditorBaseDate.Setting);
        }

        //[MenuItem("海盗猫框架/UI框架/创建配置文件")]
        public static void CreatSetting()
        {
            var creat = ScriptableObject.CreateInstance<EditorSettingScriptable>();
            AssetDatabase.CreateAsset(creat, EditorBaseDate.UISettingPath);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
}
